﻿using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string apply_id, btime, ltime;
            apply_id = Session["id"].ToString();
            btime = Session["bdata"].ToString();
            ltime = Session["ldata"].ToString();
            findappllylist(apply_id, btime,ltime);
        }
    }
    
    protected void findappllylist(string apply_id, string btime, string ltime)
    {
        sqldata dg = new sqldata();
        string str=null;
        string str1 = "SELECT id, opeartor_id, lend_id FROM applylist where id='"+apply_id+"'";
        string str2 = "SELECT id, opeartor_id, lend_id FROM applylist  WHERE  (appllytime BETWEEN '" + btime + "' AND '" + ltime + "')";
        string str3 = "SELECT id, opeartor_id, lend_id FROM applylist  WHERE  (appllytime BETWEEN '" + btime + "' AND '" + ltime + "') AND (id='" + apply_id + "')";
        if ((apply_id != "") && (btime != "" && ltime != ""))
        {
            str = str3;
        }
        else
            if (apply_id == "")
            {
                str = str2;
            }
            else
                if (btime == "" && ltime == "")
                {
                    str = str1;
                }
        dg.gridviewdatabind(str, GridView1);//数据绑定
    }

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string applly_id = this.GridView1.DataKeys[e.RowIndex].Value.ToString();
        Session["applly_id"] = applly_id;
        Response.Write("<script type=\"text/javascript\">window.open('listmessage.aspx','_blank');</script>");    
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        string id = this.GridView1.DataKeys[e.NewEditIndex].Value.ToString();
        string cmdtext = "delete from applylist where id='" + id + "'";
        string cmdtext2 = "delete from applylistpack where list_id='" + id + "'";
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["medical"].ConnectionString);
        con.Open();
        SqlCommand cmd = new SqlCommand(cmdtext, con);
        SqlCommand cmd1 = new SqlCommand(cmdtext2, con);
        cmd.ExecuteNonQuery();
        cmd1.ExecuteNonQuery();
        con.Close();
        Response.Write("<script>alert('删除" + id + "成功！！')</script>");
        Server.Transfer("findappllylistshow.aspx");
    }

}
